<?php
namespace Admin\Controller;

class TestController extends \Think\Controller{

    public function _initialize(){
        header("Content-Type: text/html; charset=utf-8");
    }
    
    public function import_member() {
        ini_set("max_execution_time", 0); 

        $Member = M('Member');
        $handle = @fopen("../data.txt", "r");
        if ($handle) {
            while (!feof($handle)) {
                $buffer = fgets($handle, 4096);
                $row = explode(",", $buffer);
                $Member->add(array('card_num' => str_replace(array("\r\n", "\n", "\r", "'"), '', $row[1]), 'member_num' => trim($row[0], "'")));
            }
            fclose($handle);
        }
    }

    public function getToken() {
        $token = new \Overtrue\Wechat\AccessToken(C('APPID'), C('APPSECRET'));
        $res = $token->getToken(true);
        dump($res);
    }

    public function openid() {
        set_time_limit(0);
        $wxMember = M('WxMember')->where('id = 1798')->select();
        foreach ($wxMember as $key => $value) {
            $member = M('Member')->where(array('openid' => $value['fromuser']))->find();dump($member);die;
            M('WxMember')->where(array('id'=>$value['id']))->save(array(
                'card_num' => $member['card_num'],
                'member_num' => $member['member_num'],
                'phone' => $member['phone']
            ));
            usleep(200);
        }
    }
    
}
